﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Northwind.Objects
{
    public class Customer: INotifyPropertyChanged
    {
        // CustomerID
        private string _CustomerID;
        public string CustomerID { 
            get { return _CustomerID; } 
            set {
                if (_CustomerID != value)
                {
                    _CustomerID = value;
                    OnPropertyChanged("CustomerID");
                }
            }
        }
        // CompanyName
        private string _CompanyName;
        public string CompanyName
        {
            get { return _CompanyName; }
            set
            {
                if (_CompanyName != value)
                {
                    _CompanyName = value;
                    OnPropertyChanged("CompanyName");
                }
            }
        }
        // ContactName
        private string _ContactName;
        public string ContactName
        {
            get { return _ContactName; }
            set
            {
                if (_ContactName != value)
                {
                    _ContactName = value;
                    OnPropertyChanged("ContactName");
                }
            }
        }
        // ContactTitle
        private string _ContactTitle;
        public string ContactTitle
        {
            get { return _ContactTitle; }
            set
            {
                if (_ContactTitle != value)
                {
                    _ContactTitle = value;
                    OnPropertyChanged("ContactTitle");
                }
            }
        }
        // Address
        private string _Address;
        public string Address
        {
            get { return _Address; }
            set
            {
                if (_Address != value)
                {
                    _Address = value;
                    OnPropertyChanged("Address");
                }
            }
        }
        // City
        private string _City;
        public string City
        {
            get { return _City; }
            set
            {
                if (_City != value)
                {
                    _City = value;
                    OnPropertyChanged("City");
                }
            }
        }
        // Region
        private string _Region;
        public string Region
        {
            get { return _Region; }
            set
            {
                if (_Region != value)
                {
                    _Region = value;
                    OnPropertyChanged("Region");
                }
            }
        }
        // PostalCode
        private string _PostalCode;
        public string PostalCode
        {
            get { return _PostalCode; }
            set
            {
                if (_PostalCode != value)
                {
                    _PostalCode = value;
                    OnPropertyChanged("PostalCode");
                }
            }
        }
        // Country
        private string _Country;
        public string Country
        {
            get { return _Country; }
            set
            {
                if (_Country != value)
                {
                    _Country = value;
                    OnPropertyChanged("Country");
                }
            }
        }
        // Phone
        private string _Phone;
        public string Phone
        {
            get { return _Phone; }
            set
            {
                if (_Phone != value)
                {
                    _Phone = value;
                    OnPropertyChanged("Phone");
                }
            }
        }
        // Fax
        private string _Fax;
        public string Fax
        {
            get { return _Fax; }
            set
            {
                if (_Fax != value)
                {
                    _Fax = value;
                    OnPropertyChanged("Fax");
                }
            }
        }

        #region Constructor
        public Customer()
        {
        }

        public Customer(string sText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sText))
                {
                    string[] M = sText.Split(new char[] { ',' }, StringSplitOptions.None);
                    CustomerID = M[0];
                    CompanyName = M[1];
                    ContactName = M[2];
                    ContactTitle = M[3];
                    Address = M[4];
                    City = M[5];
                    Region = M[6];
                    PostalCode = M[7];
                    Country = M[8];
                    Phone = M[9];
                    Fax = M[10];
                }
            }
            catch (Exception ex)
            {
            }
        }   
        #endregion Constructor End

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string pPropertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(pPropertyName));
            }
        }
    }
}
